﻿//------------------------------------------------------------------------------
// System Name:   Customer Service Platform
// Component:     CIS  Overseas CountryManagement
// Created By:    Samara Jiang (samaraj@wicresoft.com)
// Created Date:  2011-1-27
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASBCC.Business;
using ASBCC.Business.CIS;
using ASBCC.Database.EntityFramework;
using ASB.CC.Business.CIS;

namespace BEGDC.CC.Web.CIS2.Admin
{
    /// <summary>
    ///  CIS  Overseas CountryManagement
    /// </summary>
    public partial class CountryManagement : EntityPage
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override EntityDataSource EntitySource
        {
            get { return this.edsCountry; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return this.SearchText; }
        }

        protected override Button EntityAddBtn
        {
            get { return this.BtnAdd; }
        }

        protected override Button EntitySearchBtn
        {
            get { return this.Searchbtn; }
        }


        protected override Button EntityClearBtn
        {
            get { return this.Cleanbtn; }
        }

        protected override GridView EntityGrid
        {
            get { return this.gvCountry; }
        }

        protected override DetailsView EntityDetails
        {
            get { return this.dvCountry; }
        }

        protected override void OnEntityDisabling(int entityKey)
        {
            CountryManagementHelper.SetCountryInfoDisabled(entityKey);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Country disabled. id=" + entityKey + "; name=" + CountryManagementHelper.getName(entityKey));
        }

        protected override string GetEntityWhereExpression(string keyword)
        {
            return "(it.Name like N'%" + keyword + "%'"
                 + " or it.Description like N'%" + keyword + "%')";
        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {
            var dc = e.Context;
            var country = e.Entity as Country;
            var areaList = this.Request.Form["areacheck"];
            var areas = LogInfoHelper.GetAreaOverseas(areaList);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Country inserted. name=" + country.Name + "; Chinese Name=" + country.Description + areas);
            e.Cancel = true;
            CountryManagementHelper.OnCountryInserting(0, country.Name, country.Description, areaList);
        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {
            var dc = e.Context;
            var country = e.Entity as Country;
            var areaList = this.Request.Form["areacheck"];
            var areas = LogInfoHelper.GetAreaOverseas(areaList);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Country updated. id=" + country.CountryID + "; name=" + country.Name + "; Chinese Name=" + country.Description + areas);
            e.Cancel = true;
            CountryManagementHelper.OnCountryUpdating(country.CountryID, country.Name, country.Description, areaList);
        }



        protected void edsCountry_Inserted(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var country = e.Entity as Country;
            var areas = LogInfoHelper.GetAreaWithCountry(country.CountryID);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Country inserted. id=" + country.CountryID + "; name=" + country.Name + "; Chinese Name=" + country.Description + areas);
        }

        protected void edsCountry_Updated(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var country = e.Entity as Country;
            var areas = LogInfoHelper.GetAreaWithCountry(country.CountryID);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Country updated. id=" + country.CountryID + "; name=" + country.Name + "; description=" + country.Description + "; area=" + areas);
        }

    }
}
